package com.fu.xmlparse;

import org.dom4j.Attribute;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.io.File;
import java.util.List;

/**
 * @author 付大大
 * @description
 * @create 2021-01-17 14:21
 */
public class XmlParse {
    public static void main(String[] args) throws DocumentException {
        SAXReader saxReader = new SAXReader();

        Document read = saxReader.read(new File("project_classloader/src/com/fu/xml/student.xml"));

        Element rootElement = read.getRootElement();

        List<Element> student = rootElement.elements("student");

        for (Element element : student) {
            Attribute attribute = element.attribute("id");
            String id = attribute.getValue();

            Element nameElement = element.element("name");
            String name = nameElement.getText();

            Element ageElement = element.element("age");
            String age = ageElement.getText();

            System.out.println(id+"--"+name+"--"+age);

        }


    }
}
